package com.emperor.controller.userservice;

import com.emperor.entity.User;
import com.emperor.result.Result;
import com.emperor.service.UserService;
import com.emperor.vo.SkuClassPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("userServiceUser")
@RequestMapping("/user-service/user")
@Slf4j
@Api(tags = "用户管理")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/search")
    @ApiOperation("人员搜索")
    public Result<SkuClassPageVo> findAll(Integer pageIndex, Integer pageSize, String name) {
        com.emperor.vo.SkuClassPageVo vo = userService.findAll(pageIndex, pageSize, name);
        return Result.success(vo);
    }

    @ApiOperation("新增人员")
    @PostMapping
    public Result save(@RequestBody User user) {
        userService.save(user);
        return Result.success();
    }

    @PutMapping("{userId}")
    @ApiOperation("修改人员")
    public Result updateById(@PathVariable Integer userId, @RequestBody User user) {
        userService.updateById(userId, user);
        return Result.success();
    }

    @DeleteMapping("{userId}")
    @ApiOperation("删除人员")
    public Result deleteById(@PathVariable Integer userId) {
        userService.deleteById(userId);
        return Result.success();
    }
}
